using MediatR;
using MeetingManagement.Domain.Entities;
using MeetingManagement.Domain.Repositories;

namespace MeetingManagement.Application.Commands.Users.DeleteUser;

public class DeleteUserCommandHandler : IRequestHandler<DeleteUserCommand, DeleteUserResult>
{
    private readonly IRepository<User> _userRepository;
    public DeleteUserCommandHandler(IRepository<User> userRepository)
    {
        _userRepository = userRepository;
    }
    public async Task<DeleteUserResult> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
    {
        var user = await _userRepository.GetAsync(request.Id);
        if (user == null)
        {
            return new DeleteUserResult
            {
                Success = false,
                Message = "User not found"
            };
        }

        await _userRepository.DeleteAsync(user);

        return new DeleteUserResult
        {
            Success = true,
            Message = "User deleted successfully"
        };
    }
}
